﻿using System.Data;
using System.Xml;
using NazTek.Utility;

namespace NazTek.Utility.Extensions.IO
{
    /// <summary>
    /// Extends DataSet
    /// </summary>
    public static class DataSetExtension
    {
        /// <summary>
        /// Gets plain xml text represenation of the DataSet
        /// </summary>
        /// <param name="source">DataSet to serialize</param>
        /// <returns>XML string representation of the DataSet</returns>
        /// <example>
        /// <code>
        /// // &lt;DataSetName&gt;
        /// //   &lt;DataTableName&gt;
        /// //     &lt;Column1&gt;Bob&lt;/Column1&gt;
        /// //     &lt;Column2&gt;1950-04-19T00:00:00-05:00&lt;/Column2&gt;
        /// //   &lt;/DataTableName&gt;
        /// //   &lt;DataTableName&gt;
        /// //     &lt;Column1&gt;Jane&lt;/Column1&gt;
        /// //     &lt;Column2&gt;1990-01-01T00:00:00-06:00&lt;/Column2&gt;
        /// //   &lt;/DataTableName&gt;
        /// // &lt;/DataSetName&gt;
        /// MyDataSet.GetUnformattedXml();
        /// </code>
        /// </example>
        public static string GetUnformattedXml(this DataSet source)
        {
            Parameter.Validate("sourceDataSet", source, true);
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(source.GetXml());
            return doc.OuterXml;
        }
    }
}
